﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Sustainalytics.Auth.Service.GA
{
    public class GaClaimsProvider
    {
        private readonly UniversesClaimProvider _universesClaimProvider;
        private readonly UserClaimsProvider _userClaimsProvider;

        public GaClaimsProvider(
            UniversesClaimProvider universesClaimProvider,
            UserClaimsProvider userClaimsProvider)
        {
            _universesClaimProvider = universesClaimProvider;
            _userClaimsProvider = userClaimsProvider;
        }

        public virtual async Task<IEnumerable<Claim>> GetClaimsAsync(GaUser user)
        {
            var userClaims = _userClaimsProvider.GetClaims(user);
            var univesesClaim = await _universesClaimProvider.GetClaimAsync(user.AccountId ?? Guid.Empty);

            return userClaims.Concat(new[] { univesesClaim });
        }
    }
}
